home *** CD-ROM | disk | FTP | other *** search
- MODULE Automata;
-
- (* Automata is the main two-dimensional cellular automata calculator
- program, implementing all the features given to it by the Byte,
- December 1986 article.
-
- Version 1.1a by Mike Dryja March 1, 1987 *)
-
- FROM SYSTEM IMPORT NULL;
- FROM AMCalc IMPORT MaxAutomata, Automata, RuleString, Range, Same,
- Equate, NextGeneration, Initialize, CloseCalc,
- SetLength, EstablishRule;
- FROM AMSetUp IMPORT AMWindow, PrepareScreen, CloseSetUp, NewRule, OldRule,
- StringReq, AuthorReq;
- FROM AMMenu IMPORT InitMenu, Toggle, ToggleChoices;
- FROM AMGraphics IMPORT ScrollType, SetScroll, PreparePlot, PlotAutomata;
- FROM Intuition IMPORT IDCMPFlags, IDCMPFlagSet, IntuiMessage,
- IntuiMessagePtr;
- FROM Ports IMPORT GetMsg, ReplyMsg, Message, MessagePtr, WaitPort;
- FROM IntuiUtils IMPORT ItemNum, MenuNum;
- FROM Requesters IMPORT Request;
- FROM Strings IMPORT Assign;
- FROM InOut IMPORT WriteString, WriteLn;
- FROM RandomNumbers
- IMPORT Random;
- TYPE
- Normal = ARRAY[1..MaxAutomata] OF CHAR;
-
- VAR
- FirstA,
- SecondA : Automata;
- ScrollStatus : ScrollType;
- FirstAStr : Normal;
- ReStart,
- AllDone : BOOLEAN;
- MsgPtr : IntuiMessagePtr;
- Class : IDCMPFlagSet;
- Code : CARDINAL;
-
- PROCEDURE RandomAutomata (VAR auto : Normal);
- VAR
- i : CARDINAL;
- BEGIN
- FOR i := 1 TO MaxAutomata DO
- auto[i] := CHR(48 + Random(4));
- END;
- END RandomAutomata;
-
- PROCEDURE RequestRule();
- VAR
- RuleMsgPtr : IntuiMessagePtr;
- BEGIN
- IF Request(StringReq^, AMWindow^) = TRUE THEN
- REPEAT
- RuleMsgPtr := WaitPort(AMWindow^.UserPort);
- RuleMsgPtr := GetMsg(AMWindow^.UserPort);
- UNTIL (RuleMsgPtr^.Class = (IDCMPFlagSet {ReqClear}));
- ReplyMsg(MessagePtr(RuleMsgPtr));
- Assign(OldRule, NewRule);
- EstablishRule(NewRule);
- END;
- END RequestRule;
-
- PROCEDURE RequestAuthor();
- VAR
- AuthorMsgPtr : IntuiMessagePtr;
- BEGIN
- IF Request(AuthorReq^, AMWindow^) = TRUE THEN
- REPEAT
- AuthorMsgPtr := WaitPort(AMWindow^.UserPort);
- AuthorMsgPtr := GetMsg(AMWindow^.UserPort);
- UNTIL (AuthorMsgPtr^.Class = (IDCMPFlagSet {ReqClear}));
- ReplyMsg(MessagePtr(AuthorMsgPtr));
- END;
- END RequestAuthor;
-
- PROCEDURE PauseAutomata();
- VAR
- PauseMsgPtr : IntuiMessagePtr;
- TogBack : BOOLEAN;
- BEGIN
- TogBack := FALSE;
- Toggle (Resume);
- REPEAT
- REPEAT
- PauseMsgPtr := WaitPort(AMWindow^.UserPort);
- PauseMsgPtr := GetMsg(AMWindow^.UserPort);
- UNTIL (PauseMsgPtr^.Class = (IDCMPFlagSet {MenuPick}));
- ReplyMsg(MessagePtr(PauseMsgPtr));
- IF MenuNum(PauseMsgPtr^.Code) = 1 THEN
- IF (ItemNum(PauseMsgPtr^.Code)) = 0 THEN
- ScrollStatus := Coarse;
- SetScroll(ScrollStatus);
- ELSE
- ScrollStatus := Smooth;
- SetScroll(ScrollStatus);
- END;
- ELSIF MenuNum(PauseMsgPtr^.Code) = 0 THEN
- CASE (ItemNum(PauseMsgPtr^.Code)) OF
- 0 : RequestAuthor; |
- 1 : RequestRule; |
- 2 : TogBack := TRUE; |
- 3 : ReStart := TRUE;
- TogBack := TRUE; |
- 4 : AllDone := TRUE;
- TogBack := TRUE; |
- END;
- END;
- UNTIL (TogBack = TRUE);
- Toggle (Pause);
- END PauseAutomata;
-
- PROCEDURE DoMessage();
- BEGIN
- IF Class = (IDCMPFlagSet {MenuPick}) THEN
- IF MenuNum(Code) = 1 THEN
- IF (ItemNum(Code)) = 0 THEN
- ScrollStatus := Coarse;
- SetScroll(ScrollStatus);
- ELSE
- ScrollStatus := Smooth;
- SetScroll(ScrollStatus);
- END;
- ELSIF MenuNum(Code) = 0 THEN
- CASE (ItemNum(Code)) OF
- 0 : RequestAuthor; |
- 1 : RequestRule; |
- 2 : PauseAutomata; |
- 3 : ReStart := TRUE; |
- 4 : AllDone := TRUE; |
- END;
- END;
- END;
- END DoMessage;
-
- BEGIN
-
- (* One time initializations first *)
-
- IF PrepareScreen() = FALSE THEN
- WriteString("Could not prepare screen."); WriteLn;
- CloseSetUp();
- CloseCalc();
- HALT();
- END;
- InitMenu();
- SetLength(MaxAutomata);
- Initialize(FirstA);
- Initialize(SecondA);
- NewRule := "0231123003";
- Assign(OldRule, NewRule);
- ScrollStatus := Coarse;
- SetScroll(ScrollStatus);
- AllDone := FALSE;
- EstablishRule(NewRule);
-
- (* Main loop *)
-
- REPEAT
- PreparePlot();
- RandomAutomata(FirstAStr);
- Equate(FirstAStr, FirstA);
-
- LOOP
- PlotAutomata(FirstA);
- Same(FirstA, SecondA);
- NextGeneration(SecondA, FirstA);
- MsgPtr := GetMsg(AMWindow^.UserPort);
- IF MsgPtr # NULL THEN
- WHILE MsgPtr # NULL DO
- Class := MsgPtr^.Class;
- Code := MsgPtr^.Code;
- ReplyMsg(MessagePtr(MsgPtr));
- DoMessage();
- MsgPtr := GetMsg(AMWindow^.UserPort);
- END;
- IF ReStart = TRUE THEN
- ReStart := FALSE;
- EXIT;
- END;
- IF AllDone = TRUE THEN
- EXIT;
- END;
- END;
- END;
- UNTIL AllDone = TRUE;
-
- (* Close everything down *)
-
- CloseSetUp();
- CloseCalc();
- END Automata.
-
-